<template>
  <work-template @submitOn="submitOn" v-model="ruleForm"
                 @closeSelectedTag="closeSelectedTag" :butShow="bool">
    <div slot="form" class="container-div">
      <!--车辆信息  订单信息-->
      <vehicleMessage v-model="ruleForm" :state="isEdit"  ref="refVehicleMessage"/>
      <!--申请信息-->
      <applyForMessage v-model="ruleForm" :state="isEdit" ref="refApplyForMessage"/>
    </div>

  </work-template>
</template>

<script>
import {ScrapHandleNew} from '@/api/vehicleDisposal/scrapHandle.js'

export default {
  name: 'ScrapHandleNew',//新增
  components: {
    vehicleMessage: () => import('../../components/scrapDisposal/vehicleMessage.vue'),
    applyForMessage: () => import('../../components/scrapDisposal/applyForMessage.vue'),
  },
  computed: {
    isEdit() {
      if (this.$route.query.type === "edit") {
        return "write";
      }
      if (this.$route.query.type === "view") {
        return "readonly";
      }
    },
    bool() {
      if (this.$route.query.type === "edit") {
        return true;
      }
      if (this.$route.query.type === "view") {
        return false;
      }
    },
  },
  watch: {},
  data() {
    return {
      ruleForm: {
        carId: null,
        carNo:'',
        vinNo:'',
        brandId: '',
        seriesId: '',
        modelId: '',
        brandName: '',
        modelName: '',
        seriesName: '',
        propertyRightId: '',
        propertyRightName: '',
        operationsName:'',
        operationsId:'',
        ascriptionId:'',
        ascription:'',
        rentInsuranceCompany:'',
        compensationClaims:'',
        maintenanceNo:'',
        scrapPassedTime:'',
        financialPassedTime:'',
        orderNo:'',
        schemeName:'',
        customerName:'',
        disposalScrapDetails:'',
        disposalScrapAttachment:''
      }
    };
  },
  created() {
  },
  mounted() {
  },
  methods: {
    submitOn() {
      let arr = [
        this.$refs.refVehicleMessage.handleEffect(),
        this.$refs.refApplyForMessage.handleEffect(),
      ]
      Promise.all(arr).then(() => {
        const loading = this.$loading({
          lock: true,
          text: '保存中',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        })
        ScrapHandleNew(this.ruleForm).then(res => {
          if (res.code === 200) {
            this.$message.success('保存成功')
            loading.close()
            this.closeSelectedTag()
          }
        }).catch(() => {
          loading.close()
        })
      }).catch(() => {
      })
    },

    closeSelectedTag(view) {
      this.$tab.closePage(view).then(({visitedViews}) => {
        this.$router.push({
          path: "/VehicleDisposal/ScrapDisposal/ScrapHandleList",
        });
      });
    }
  },
};
</script>

<style scoped lang=""></style>


